package com.bjpowernode.services;

import com.bjpowernode.beans.NewsType;
import com.bjpowernode.exception.MyException;
import com.bjpowernode.mapper.NewsTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class NewsTypeServicesImp implements NewsTypeServices {

    //@Autowired自动注入，那么如果一个接口有N个实现
    //@Autowired自动注入是按照类型的，也就是ByType，换句话说，你的接口必须只有一个实现
    //@Autowired可以配合@Qualifier按照ByName选择你需要注入的子类
//    @Autowired
//    @Qualifier(value = "newsTypeMapper")

    @Autowired
    NewsTypeMapper newsTypeMapper;


    @Override
    public ArrayList<NewsType> getAll() {
        return newsTypeMapper.getAll();
    }

    @Override
    public NewsType get(int id) {
        return newsTypeMapper.get(id);
    }

    @Override
    public void add(NewsType newsType) throws MyException {

        int add = newsTypeMapper.add(newsType);
        if(add<=0){
            throw new MyException("新闻类型添加失败，没有影响行数");
        }

    }

    @Override
    public void edit(NewsType newsType) throws MyException {

        int edit = newsTypeMapper.edit(newsType);
        if(edit<=0){
            throw new MyException("新闻类型修改失败，没有影响行数");
        }
    }

    @Override
    public void del(int id) throws MyException {
        int del = newsTypeMapper.del(id);
        if(del<=0){
            throw new MyException("新闻类型删除失败，没有影响行数");
        }
    }
}
